import './assets/css/style.css';

import './assets/js/xmind';
var xmind = null;
fn_init();
function fn_init(){
    let newData = [
        {id:"root",root:true,pid:null,label:"xmid"},
        {id:"r1",pid:"root",label:"的奋达科技骄傲了快递师傅埃里克定时发送法律是假的发了看电视就发了多少",left:false,nodeStyleCls:"aaaa",nodeDivClass:['a','b']},
        {id:"r11",pid:"r1",label:"r11",left:false},
        {id:"r12",pid:"root",label:"r12",left:false},
        {id:"r112",pid:"root",label:"r112",left:false},
        // {id:"r2",pid:"root",label:"r2",left:false},
        // {id:"r21",pid:"r2",label:"r21",left:false},
        // {id:"r22",pid:"r2",label:"r22",left:false},
        // {id:"l1",pid:"root",label:"l1",left:true},
        // {id:"l11",pid:"l1",label:"l11",left:true},
        // {id:"l12",pid:"l11",label:"l12",left:true},
        // {id:"l2",pid:"root",label:"l2",left:true},
    ];
    xmind = new $xmind({
        selector:"xmind",
        data:[],
        style:{
            node:{
                hasIcon:true,
            }
        },
        // hawkEye:{
        //     open:true,
        //     pid:'narrow',
        // },
        nodeLimit:100,
        nodePriorityCls:{
            rule:{
                nodeStyleCls:"node-priority-mid",
                nodeIcon    :"dIcon-node-rule",
            },
            compute:{
                nodeStyleCls:"node-priority-mid",
                nodeIcon    :"dIcon-node-compute",
            },
            resource:{
                nodeStyleCls:"node-priority-mid",
                nodeIcon    :"dIcon-node-resource",
            },
            currency:{
                nodeStyleCls:"node-priority-mid",
                nodeIcon    :"dIcon-node-rule",
            },
        },
        nodeStateCls:{          // 节点状态样式
            ing:"1",
            success:"2",
            fail:"0"
        },
    });
    xmind.setNodes(newData,()=>{
        // fn_echarts1.call(this)
        xmind.canvasCenter()
    });
    xmind.highlightNodes([
        {id:'r1'},
        {id:'r11'},
    ])
}


function fn_echarts1(){
    // 基于准备好的dom，初始化echarts实例
    let xmdEcharts = document.getElementById('xmdEcharts');
    let xpar = xmdEcharts.parentNode;
    if(xmdEcharts)xpar.removeChild(xmdEcharts);
    let newXmd = document.createElement('div');
    newXmd.setAttribute('id','xmdEcharts');
    newXmd.setAttribute('class','xmd-echart');
    xpar.appendChild(newXmd);
    var myChart = this.$echarts.init(newXmd);

    // 指定图表的配置项和数据
    var option = {
        title: {
            text: 'ECharts 入门示例'
        },
        tooltip: {},
        legend: {
            data:['销量']
        },
        xAxis: {
            data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
        },
        yAxis: {},
        series: [{
            name: '销量',
            type: 'bar',
            data: [5, 20, 36, 10, 10, 20]
        }]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
}



// xmind.setNodeState({
//     id:"r1",
//     state:0
// })

// setTimeout(()=>{
//     xmind.setContentMenu({
//         type:"canvas",
//         items:[
//             {label:"保存解决方案",id:"saveTactic",name:"canvas",is:false,fn:(res)=>{
//                 console.log("outside",res)
//             }}
//         ]
//     });

//     xmind.setContentMenu({
//         type:"node",
//         items:[
//             {label:"属性",id:"default",name:"node",is:false,fn:(res)=>{
//                 console.log("outside",res)
//             }}
//         ]
//     });nodeDrag
// })

xmind.on('contactLineEvt',(e,res)=>{
    console.log('contactLineEvt',res)
    
});
// xmind.off();

// xmind.switchDraw(true);

// xmind.on('nodeCntMenu',(e,res)=>{
//     console.log('nodeCntMenu',res)
//     // console.log(xmind.getNodesFree())
// });

// xmind.on('nodeDrag',(e,res)=>{
//     console.log('nodeDrag',res)
//     // console.log(xmind.getNodesFree())
// });

xmind.on('nodeDblclick',(e,res)=>{
    console.log('nodeDblclick',res)
});

// xmind.on('nodeAdd',(e,res)=>{
//     console.log(res)
// });

// xmind.on('nodeDel',(e,res)=>{
//     console.log(res)
// });

// xmind.on('undoRedoOpt',(e,res)=>{
//     console.log(res)
// });

// xmind.on('temporaryLineUp',(e,res)=>{
//     console.log(res)
// });
// xmind.setZoom("narrow")
// xmind.setZoom("narrow")

let tt = document.getElementById("test");
tt.onmousedown = (e)=>{
    xmind.createdDraw({
        id:"test111",
        label:"newDraw",
        type:"compute",
        e,
    })
}

let enlarge = document.getElementById('enlarge');
enlarge.onclick = ()=>{
    // fn_init()
    // xmind.destroyed();
    xmind.hawkEye(false)
    // let tree = xmind.getNodesTree();
    // let free = xmind.getNodesFree();
    // xmind.resetCntMenu({has:false})
    
    // // xmind.setNodes(tree);
    // console.log("tree",tree);
}


// let narrow  = document.getElementById('narrow');

// let enlarge = document.getElementById('enlarge');
let narrow  = document.getElementById('narrow');

// enlarge.onclick = ()=>{
//     xmind.setZoom('enlarge')
// }

narrow.onclick = ()=>{
    xmind.hawkEye(true,'narrow')
    // xmind.setZoom('narrow')
}

// import './assets/js/menu';